package cn.doitedu.day02

/**
 * 对数组或集合中的数据进行聚合操作
 */
object ReduceDemo {

  def main(args: Array[String]): Unit = {


    val arr = Array(2, 5 ,1 , 8, 9, 8 ,3,5,7,6,4,2,9)
    //求和
    val r1: Int = arr.sum
    //调用reduce

    val f2 = (a: Int, b: Int) => a + b
    val r2: Int = arr.reduce(f2)

    val r3 = arr.reduce((x, y) => x + y)

    val r4 = arr.reduce(_ + _)

    println(r2)




  }

}
